import { InputItem } from '@/components';
import DepartmentController from '@/services/System/DepartmentController';
import { message,Modal } from 'antd';
import React from 'react';
const {confirm} = Modal
class Detail extends React.Component {
    constructor(props) {
        super(props);
        this.state = { 
            datas:props.rowData||{},
            rowData:props.rowData,
            type:props.type
         };
    }
    componentDidMount(){
        this.props.onRef(this)
    }
    handleChange=(datas)=>{
        this.setState({datas})
    }
    submit=()=>{
        let {datas,type,rowData} = this.state
        let that = this
        console.log(datas)
        // if(!datas.code){
        //     message.error('请输入部门编码')
        //     return
        // }
        if(!datas.name){
            message.error('请输入部门名称')
            return
        }
        if(!datas.type){
            message.error('请选择部门级别')
            return
        }
        confirm({
            title:'提示',
            content:'确定要提交吗？',
            onOk(){
                if(type===1){
                    DepartmentController.createdSubmit(datas).then(r=>{
                        if(r&&r.status===200){
                            message.success('提交成功')
                            that.props.onCancel()
                        }
                    })
                }
                if(type===2){
                    datas.id=rowData.id
                    DepartmentController.updateSubmit(datas).then(r=>{
                        if(r&&r.status===200){
                            message.success('提交成功')
                            that.props.onCancel()
                        }
                    })
                }
                
            }
        })

    }
    render() {
        const {datas}=this.state
        const columns=[
            {name:'名称',keyName:'name',valueType:'text',value:datas.name||''},
            // {name:'编码',keyName:'code',valueType:'text',value:datas.code||''},
            {name:'级别',keyName:'type',valueType:'select',value:datas.type||'',selectDatas:[{code:'省级',name:'省级'},{code:'市级',name:'市级'}]},
            {name:'是否禁用',keyName:'to_stop',valueType:'select',value:datas.toStop||'',selectDatas:[{code:'1',name:'正常'},{code:'2',name:'禁用'}]},
        ]
        return (
            <div>
                <InputItem columns={columns}  onChange={this.handleChange}/>
            </div>
        );
    }
}

export default Detail;